<?php
/**
 * Created by PhpStorm.
 * User: Emmett
 * Date: 2016/8/30
 * Time: 17:30
 */

namespace Business\Custom;

use Business\StrategyBase;
use Think\Page;


abstract class CustomStrategyBase extends StrategyBase implements iCustomStrategy
{
    public function index()
    {
        $this->mvc_controller->assign('Custom_Registered_Status', C('Custom_Registered_Status'));
        $this->mvc_controller->assign('Custom_Type', C('Custom_Type'));
        $this->mvc_controller->assign('Custom_Trade', C('Custom_Trade'));
        $this->mvc_controller->assign('Custom_Target_Product', C('Custom_Target_Product'));
        $this->mvc_controller->assign('Custom_Source', C('Custom_Source'));

        $model = D('CrmCustom');
        $sp = $_GET['p'];
        if (empty($sp)) {
            $sp = 1;
        }

        $search_key = $_GET['search_key'];
        $search_type = $_GET['search_type'];
        $search_trade = $_GET['search_trade'];
        $search_distribute = $_GET['search_distribute'];

        $cuser = $this->mvc_controller->current_user;

        $list = $model->get_list($cuser['id'], $search_key, $search_type, $search_distribute, $sp, C('PAGE_SIZE'));

        $page = new Page($list[1], C('PAGE_SIZE'));

        $this->mvc_controller->assign('total_rows', $page->totalRows);
        $this->mvc_controller->assign('_page', $page);
        $this->mvc_controller->assign('page_link', $page->show());
        $this->mvc_controller->assign('custom_list', $list[0]);

        foreach ($_GET as $key => $val) {
            $page->parameter[$key] = urlencode($val);
        }
    }

    public function sea()
    {
        $this->mvc_controller->assign('Custom_Type', C('Custom_type'));

        $model = D('CrmCustom');
        $sp = $_GET['p'];
        if (empty($sp)) {
            $sp = 1;
        }
        $search_key = $_GET['search_key'];
        $search_type = $_GET['search_type'];
        $search_distribute = $_GET['search_distribute'];

        $list = $model->get_sea_list(null, $search_key, $search_type, $search_distribute, $sp, C('PAGE_SIZE'));

        $page = new Page($list[1], C('PAGE_SIZE'));

        $this->mvc_controller->assign('total_rows', $page->totalRows);
        $this->mvc_controller->assign('_page', $page);
        $this->mvc_controller->assign('page_link', $page->show());
        $this->mvc_controller->assign('custom_list', $list[0]);

        foreach ($_GET as $key => $val) {
            $page->parameter[$key] = urlencode($val);
        }
    }

    public function signed()
    {
        $this->mvc_controller->assign('Custom_Type', C('Custom_type'));

        $model = D('CrmCustom');
        $sp = $_GET['p'];
        if (empty($sp)) {
            $sp = 1;
        }
        $search_key = $_GET['search_key'];
        $search_type = $_GET['search_type'];
//        $search_distribute = $_POST['search_distribute'];
        $search_distribute = 2;
        $cuser = $this->mvc_controller->current_user;
        $list = $model->get_singed_list($cuser['id'], $cuser['id'], $search_key, $search_type, $search_distribute, $sp, C('PAGE_SIZE'));

        $page = new Page($list[1], C('PAGE_SIZE'));

        $this->mvc_controller->assign('total_rows', $page->totalRows);
        $this->mvc_controller->assign('_page', $page);
        $this->mvc_controller->assign('page_link', $page->show());
        $this->mvc_controller->assign('custom_list', $list[0]);

        foreach ($_GET as $key => $val) {
            $page->parameter[$key] = urlencode($val);
        }
    }
}